package com.itheima.mapper;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.PageResult;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.BeanMetadataAttribute;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ClazzMapper {

    @Select("select  * from clazz")
    List<Clazz> list();

    @Insert("insert into clazz(name, room, begin_date, end_date, master_id, subject, create_time, update_time) values (#{name}, #{room}, #{beginDate}, #{endDate}, #{masterId}, #{subject}, now(), now())")
    void add(Clazz clazz);

    List<Clazz> findAll(@Param("name") String name, @Param("begin") LocalDate begin, @Param("end") LocalDate end);

    @Delete("delete from clazz where id =#{id} ")
    void delete(Integer id);

    @Select("select * from clazz where id = #{id}")
   // @Select("select id, name,room,begin_date,end_date,master_id,subject,create_time,update_time from clazz where id =#{id}")
    Clazz getById(Integer id);

    @Update("update clazz set name=#{name},room=#{room},begin_date=#{beginDate},end_date=#{endDate},master_id=#{masterId},subject=#{subject},update_time=#{updateTime} where id=#{id}")
    void update(Clazz clazz);

    @Select("select name from clazz where id=#{id}")
    String findNameById(Integer clazzId);

    @Select("select count(*) from student where clazz_id=#{id}")
    int countByClazzId(Integer id);
}
